"""文本相似度服务"""
import logging

from app.models.legalbert import calculate_similarity
from app.schemas.requests import SimilarityResponse

logger = logging.getLogger(__name__)


async def calculate_similarity_service(text1: str, text2: str) -> SimilarityResponse:
    """
    计算文本相似度服务
    
    Args:
        text1: 第一个文本
        text2: 第二个文本
        
    Returns:
        相似度结果
    """
    try:
        # 计算相似度
        similarity_score = calculate_similarity(text1, text2)
        
        return SimilarityResponse(
            text1=text1,
            text2=text2,
            similarity=similarity_score
        )
    except Exception as e:
        logger.error(f"文本相似度计算失败: {str(e)}", exc_info=True)
        raise ValueError(f"文本相似度计算失败: {str(e)}")

